#include <stdio.h>
#include <stdlib.h>
int fuction(int x)
{
    if(x<3)return x;
    else if(x>=3&&x%3==0)return fuction(x/3)*2;
    else if(x>=3&&x%3==1)return fuction((x-1)/3)+1;
    else return fuction((x-2)/3)+2;
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",fuction(n));
    return 0;
}
